package zy04;

public class MyThread extends Thread{
	private volatile boolean isNumberTurn = true;

    public synchronized void printNumber(int num) {
        while (!isNumberTurn) {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.print(num);
        System.out.print(num + 1);
        isNumberTurn = false;
        notify();
    }

    public synchronized void printLetter(char letter) {
        while (isNumberTurn) {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.print(letter);
        isNumberTurn = true;
        notify();
    }

}
